using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Projects;

namespace AndyPike.Unfuddle.Commands.Projects
{
    /// <summary>
    /// Provides a command for returning a single project by id for a given account
    /// </summary>
    public class FindProjectById : IUnfuddleFindCommand<Project>
    {
        private readonly int projectId;

        /// <summary>
        /// Instantiates the FindProjectById command
        /// </summary>
        /// <param name="projectId">The id of the project to return</param>
        public FindProjectById(int projectId)
        {
            this.projectId = projectId;
        }

        /// <summary>
        /// Queries the Unfuddle server for a project with a given id
        /// </summary>
        /// <param name="service">The Unfuddle service to use when executing the command</param>
        /// <returns>Returns a project with the matching id</returns>
        public Project Execute(IUnfuddleService service)
        {
            GuardAgainst.ArgumentNull(service, "service");

            string url = service.BuildUrl("projects/{0}", projectId);
            return service.InvokeRequest<Project>(url);
        }
    }
}